# 导入标定数据程序
import os
import numpy as np

# 图像导入路径列表
img_load_dir = ['tmp_img/tmp3', 'tmp_img/tmp27', 'tmp_img/tmp57']
# 点云导入路径结果
pcd_load_dir = ['tmp_pcd/tmp1', 'tmp_pcd/tmp9', 'tmp_pcd/tmp19']
pcd_data_list = []
img_data_list = []


for pcd_data in pcd_load_dir:
    pcd_calib_dict = {}
    data_list = os.listdir(pcd_data)
    for file_name in data_list:
        if file_name.split('.')[-1] == 'txt':
            tmp_data = np.loadtxt(pcd_data + '/' + file_name)
            tmp_pcd = []
            for i_row in range(3):
                tmp_pcd.append(np.mean(tmp_data[:, i_row]))
            pcd_calib_dict[file_name.split('.')[0]] = tmp_pcd.copy()
    pcd_data_list.append(pcd_calib_dict.copy())

for i_img, img_dir in enumerate(img_load_dir):
    file_list = os.listdir(img_dir)
    if 'classes.txt' in file_list:
        img_calib_dict = {}
        class_list = []
        with open(img_dir + '/' + 'classes.txt', 'r', encoding='utf-8') as file:
            for line in file:
                class_list.append(line.split('\n')[0])
        tmp_file = None
        for file in file_list:
            if file != 'classes.txt':
                tmp_file = file
        data_tmp = np.loadtxt(img_dir + '/' + tmp_file)
        n_d, m_d = data_tmp.shape
        for i_d in range(n_d):
            classes = class_list[int(data_tmp[i_d, 0])]
            img_calib_dict[classes] = data_tmp[i_d, 1:]
        img_data_list.append(img_calib_dict.copy())
print(img_data_list)
print(pcd_data_list)

